<template>
  <view class="my-cars">
    <!-- 有数据时显示车辆列表 -->
    <view v-if="carList.length > 0">
      <view class="car-list">
        <view class="car-item" v-for="(car, index) in carList" :key="index">
          <view class="car-info">
            <image class="car-image" :src="car.image" mode="aspectFill"/>
            <view class="car-details">
              <view class="car-model">车型：{{car.model}}</view>
              <view class="car-number">车牌：{{car.plateNumber}}</view>
            </view>
          </view>
          <view class="car-status">
            <text class="status-tag" :class="{ default: index !== defaultIndex }" @tap="toggleDefault(index)">
              <view class="check-circle" :class="{ 'has-image': defaultIndex === index }">
                <image v-if="defaultIndex === index" src="/static/组 5@2x.png" mode="aspectFit"/>
              </view>
              设为默认车辆
            </text>
            <text class="delete">删除</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 无数据时显示空状态 -->
	<view v-else class="emp">
    <view  class="empty-state">
		
      <image src="/static/组 6.png" mode="aspectFit" class="empty-image"/>
      <text class="empty-text">暂无车辆信息</text>
	
    </view>
         </view>
    <!-- 底部添加按钮 -->
    <view class="add-car-btn">
      <button type="button">添加车辆</button>
    </view>
  </view>
</template>



<script>
export default {
  name: 'MyCars',
  data() {
    return {
      defaultIndex: 0,
      succ: 0,
      carList: [] // 车辆列表数据
    }
  },
  created() {
    // 模拟获取数据
    this.getCarList()
  },
  methods: {
    toggleDefault(index) {
      this.defaultIndex = this.defaultIndex === index ? 1 : index
    },
    getCarList() {
      // 这里模拟数据，实际使用时替换为真实的接口调用
    this.carList = [
            {
              image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.Kmf4zZBeKKIdBw8C3RqmSgHaE8?w=250&h=180&c=7&r=0&o=5&dpr=1.4&pid=1.7',
              model: '奔驰-GR',
              plateNumber: '豫M35468'
            },
            {
              image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.Kmf4zZBeKKIdBw8C3RqmSgHaE8?w=250&h=180&c=7&r=0&o=5&dpr=1.4&pid=1.7',
              model: '奔驰-GR',
              plateNumber: '豫M35422'
            }
          ]
    }
  }
}
</script>
<style lang="scss" scoped>
page {
background-color: #2D80F9;
  
}

.my-cars {
  min-height: 100vh;
  background-color: #f7f7f7;
  margin-top: 15px;
}

.car-list {
  height: 200rpx;
  background-color: #2D80F9;
}

.car-item {
  margin: 0 15px;
  background: #fff;
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);

  .car-info {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
  }

  .car-image {
    width: 80rpx;
    height: 80rpx;
    object-fit: cover;
    border-radius: 50px;
    margin-right: 12px;
  }

  .car-details {
    flex: 1;

    .car-model {
      font-size: 15px;
      color: #333;
      margin-bottom: 8px;
      font-weight: 500;
    }

    .car-number {
      font-size: 13px;
      color: #666;
    }
  }

  .car-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;

    .status-tag {
      font-size: 13px;
      color: #666;
      display: flex;
      align-items: center;

      &::before {
        content: none;
      }

      .check-circle {
        display: inline-block;
        width: 16px;
        height: 16px;
        border: 0.1rpx solid #999;
        border-radius: 50%;
        margin-right: 6px;
        position: relative;
        vertical-align: middle;
        overflow: hidden;

        image {
          position: absolute;
          width: 100%;
          height: 100%;
          top: 0;
          left: 0;
          transform: none;
        }

        &.has-image {
          border: none;
        }
      }

      &.default .check-circle {
        border-color: #999;
      }
    }

    .delete {
      font-size: 13px;
   
    }
  }
}

.add-car-btn {
  position: fixed;
  bottom: 20px;
  left: 15px;
  right: 15px;

  button {
    width: 100%;
    height: 33px;
   background-color: #2D80F9;
    color: #fff;
    border: none;
    border-radius: 22px;
    font-size: 15px;
    font-weight: normal;
    display: flex;
    align-items: center;
    justify-content: center;

    &::before {
      content: '+';
      font-size: 18px;
      margin-right: 4px;
    }
  }
}
.emp{
	height: 200rpx;
	background-color: #3385FD;
}

// 添加空状态样式
.empty-state {
	background-color: white;
	border-radius: 20rpx;
	height: 60vh;
	margin: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 200rpx;
  
  .empty-image {
    width: 240rpx;
    height: 240rpx;
    margin-bottom: 20rpx;
  }
  
  .empty-text {
    font-size: 28rpx;
    color: #999;
  }
}
</style>